/**
 * zmn文章模块-文章编辑
 * 文件命名格式：zmn.模块.表/功能.jas
 * @author duanzuocai
 * @since 2018/10/18
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var layedit = layui.layedit;
    var laydate = layui.laydate;

    form.render(null, "zmn-form");

    // 自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 2){ return "分类名称不能少于2个字符"; };
        },
        sort: function(value){
            if (!/^[0-9]+$/.test(value)) {
                return "排序值只能是正整数";
            }
        }
    });

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var data = obj.field;
        var url = "/mc/dept/addEdit.action";
        data.keyStaffs = $('select[name="keyStaffId"]').find('option:selected').text();
        // "1000000/1000001/1000002/1000004,1000017,1000010"
        // if (data.orgId == null || data.orgId == "") {
        //     zmnUtil.alert("请选择组织架构");
        //     return false;
        // }
        // if (data.orgId.split(",").length > 1) {
        //     zmnUtil.alert("组织架构只能选择一个");
        //     return false;
        // }

        // var id = data.orgId.split("/");
        // data.orgId = id[id.length - 1];
        var openId = layer.open({type: 3});

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(json) {
                layer.close(openId);
                layer.msg(json.message);
                if(json.status == 200) {
                    setTimeout(function () {
                        parent.layui.element.tabChange('layadmin-layout-tabs', "/system/organ/departments.action?orgId="+obj.field.orgId+"&flag=2");
                        parent.layui.element.tabDelete('layadmin-layout-tabs', window.location.pathname + window.location.search);
                    },1000)
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){}
        })
        return false;
    });

    //对外暴露的接口
    exports('art_organ_dept_detail', {});
});
